package com.itheima.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class ServletDemo03 extends HttpServlet {
//    private ServletConfig config;

//    @Override
//    public void init(ServletConfig config) throws ServletException {
//        this.config=config;
//    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String encoding = config.getInitParameter("encoding");
//        System.out.println(encoding);
//        System.out.println("----------------------");
//        Enumeration<String> keys = config.getInitParameterNames();
//        while (keys.hasMoreElements()){
//            String key = keys.nextElement();
//            String value = config.getInitParameter(key);
//            System.out.println(key+","+value);
//        }
//        System.out.println("----------------------");
//        String servletName = config.getServletName();
//        System.out.println(servletName);
        ServletContext context = getServletContext();
        Object username = context.getAttribute("username");
        System.out.println(username);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
